/**
 * @description shop router
 */

const router=require('koa-router')()
const {SuccessModel}=require('../res-model/index')
const {
    getHotList,
    getShopById,
    getProducts,
}=require('../controller/shop')

router.prefix('/api/shop')

//商店列表

router.get('/hot-list',async function(ctx,next){
    //获取列表
    const list=await getHotList()
    ctx.body=new SuccessModel(list)
})

//单个商店信息

router.get('/:id',async function(ctx,next){
    const id=ctx.params.id
    const shop=await getShopById(id)
    ctx.body=new SuccessModel(shop)
})


//获取商店的商品

router.get('/:id/products',async function(ctx,next){
    const shopId=ctx.params.id
    const tab=ctx.query.tab || 'all'
    const list=await getProducts(shopId,tab)
    ctx.body=new SuccessModel(list)
})

module.exports=router